package com.ruicar.afs.cloud.risk.api.controller;

import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.risk.api.dto.tortoise.TortoiseQueryBean;
import com.ruicar.afs.cloud.risk.api.dto.tortoise.TortoiseResultNotice;
import com.ruicar.afs.cloud.risk.api.dto.tortoise.notice.*;
import com.ruicar.afs.cloud.risk.api.dto.tortoise.request.GwtExposureData;
import com.ruicar.afs.cloud.risk.api.dto.tortoise.request.TortoiseExposureReq;
import com.ruicar.afs.cloud.risk.api.notice.TortoiseNoticeProcessor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author Peng Jinbo
 * @Date 2020/07/31 11:28
 */
@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("/credit/apis/tortoise")
public class RiskControlTortoiseController {

    /**
     * Tortoise notice processor
     */
    private TortoiseNoticeProcessor tortoiseNoticeProcessor;

    @PostMapping("/applyNotice")
    public IResponse applyNotice(@RequestBody TortoiseResultNotice<TortoiseApplyNoticeInfo> notice){
        tortoiseNoticeProcessor.normalApply(notice);
        return IResponse.success(CommonConstants.SUCCESS);
    }

    @PostMapping("/prevNotice")
    public IResponse prevNotice(@RequestBody TortoiseResultNotice<TortoisePrevApproveNoticeInfo> notice){
        tortoiseNoticeProcessor.prevApprove(notice);
        return IResponse.success(CommonConstants.SUCCESS);
    }

    @PostMapping("/fraudPushNotice")
    public IResponse fraudPushNotice(@RequestBody TortoiseResultNotice<TortoiseFraudPushNoticeInfo> notice){
        tortoiseNoticeProcessor.fraudPush(notice);
        return IResponse.success(CommonConstants.SUCCESS);
    }

    @PostMapping("/handFraudNotice")
    public IResponse handFraudNotice(@RequestBody TortoiseResultNotice<TortoiseHandFraudNoticeInfo> notice){
        tortoiseNoticeProcessor.handFraud(notice);
        return IResponse.success(CommonConstants.SUCCESS);
    }

    @PostMapping("/handDecisionNotice")
    public IResponse handDecisionNotice(@RequestBody TortoiseResultNotice<TortoiseHandDecisionNoticeInfo> notice){
        tortoiseNoticeProcessor.handDecision(notice);
        return IResponse.success(CommonConstants.SUCCESS);
    }

    @PostMapping("/image")
    public IResponse<String> image(@RequestBody String applyNo) {
        return IResponse.success(tortoiseNoticeProcessor.getImage(applyNo));
    }

    @PostMapping("/exposure")
    public IResponse<List<GwtExposureData>> exposure(@RequestBody TortoiseExposureReq exposureReq){
        return IResponse.success(tortoiseNoticeProcessor.getExposureData(exposureReq));
    }

    @GetMapping("/data")
    public IResponse<TortoiseQueryBean> data(@RequestParam("mainId") String mainId,@RequestParam("scene")String scene) {
        return IResponse.success(tortoiseNoticeProcessor.getData(mainId,scene));
    }
}
